import 'package:flutter/material.dart';

class GridExDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    List<Container> _buildTitleList(int count) {
      return List.generate(
          count,
          (int index) => Container(
                child: Image.asset('images/card0${index + 1}.png',
                    fit: BoxFit.cover),
              )
      );
    }

    Widget _buildGrid() => GridView.extent(
          maxCrossAxisExtent: 150.0,          //item最大宽度
          padding: const EdgeInsets.all(4.0), //内边距
          mainAxisSpacing: 4.0,               //主轴item间距
          crossAxisSpacing: 4.0,              //次轴item间距
          children: _buildTitleList(9),
        );

    return Scaffold(
      appBar: AppBar(
        title: Text('GridView布局示例'),
      ),
      body: Center(
        child: _buildGrid(),
      ),
    );
  }
}
